﻿// See https://aka.ms/new-console-template for more information


using Command.CommunityToolkit.Commands;
using Command.CommunityToolkit.Helpers;
using Command.CommunityToolkit.Log4Net;
using Command.CommunityToolkit.Services.Impl;
using ICommand = Command.CommunityToolkit.Commands;


namespace Command.CommunityToolkit.Sample;

public class Program
{
    private static int SUCCESS = 0;
    private static int FAIL = 1;
    private static int UNKNOWN_COMMAND = 2;
    static int Main(string[] args)
    {
        var instance = ServiceProviderHelper.GetInstance();
        var serviceCollection = instance.ServiceCollection;
        serviceCollection.AddSingleton<ConfigurationManager, ConfigurationManager>();
        serviceCollection.AddLog4Net();
        serviceCollection.AddTransient<IQualityControl, QualityControl>();
        serviceCollection.AddTransient<CommandFactory, CommandFactory>();

        instance.ServiceProvider = serviceCollection.BuildServiceProvider();

       

        if (!args.Any())
            args = new[] { "default", "" };
        ICommand.ICommand? command = new CommandFactory().BuildCommand(args);
        if (!Equals(null, command))
            return command.Excute() ? SUCCESS : FAIL;
        else
        {
            Console.WriteLine("错误命令；查看如下具体命令及使用方式");
            new CommandFactory().BuildCommand(new[] { "help", "" })?.Excute();
            return UNKNOWN_COMMAND;
        }
    }
}